#ifndef CONTROLPOINT_H
#define CONTROLPOINT_H
#include <QLabel>


class ControlPoint : public QLabel
{
    Q_OBJECT
public:
    explicit ControlPoint(QWidget *parent = nullptr);

    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);
    void mouseMoveEvent(QMouseEvent *ev);
    void mousePressEvent(QMouseEvent *ev);
    void mouseReleaseEvent(QMouseEvent *ev);

    bool event(QEvent *e);

    void setMiddle(int x, int y);
    QPoint getMiddle(){return middle;}
    QPoint getRight(){return rightDir;}
    QPoint getLeft(){return leftDir;}
    void setRight(float x, float y);

    //绘图事件
    void paintEvent(QPaintEvent *);
signals:

private:
    // 根据坐标点更新位置和大小
    void updateBox();
    int drag=0; // 0: 没有东西点中，1中心，2left, 3right
    QPoint lastPos;
    float leftLen, rightLen;
    QPoint middle, leftDir, rightDir; // middle是在父窗口的坐标，leftdir, rightdir是相对于middle的向量
};

#endif // CONTROLPOINT_H
